package userinterface;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainWindow extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel mainPanel = null;
	private JTextField tfInitialDirectory = null;
	private JButton btnBrowser = null;
	private JFileChooser fcOpenDirectory = null;
	private JLabel lblInitialDirectory = null;
	private JButton btnSave = null;
	private JButton btnCancel = null;

	/**
	 * This is the default constructor
	 */
	public MainWindow() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * @return void
	 */
	private void initialize() {
		this.setSize(411, 148);
		this.setForeground(new Color(0, 102, 102));
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(
				getClass().getResource("/images/Defragmentation.png")));
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(getJContentPane());
		this.setTitle("Hawar Config");
	}

	/**
	 * This method initializes jContentPane
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new CardLayout());
			jContentPane.add(getMainPanel(), getMainPanel().getName());
		}
		return jContentPane;
	}

	/**
	 * This method initializes mainPanel
	 * @return javax.swing.JPanel
	 */
	private JPanel getMainPanel() {
		if (mainPanel == null) {
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 2;
			gridBagConstraints3.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints3.gridy = 2;
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 1;
			gridBagConstraints21.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints21.gridy = 2;
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.gridx = 0;
			gridBagConstraints11.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints11.gridy = 0;
			lblInitialDirectory = new JLabel();
			lblInitialDirectory.setText("Initial Directory");
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.fill = GridBagConstraints.BOTH;
			gridBagConstraints2.gridy = 1;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 3;
			gridBagConstraints1.insets = new Insets(5, 0, 5, 5);
			gridBagConstraints1.gridy = 0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints.gridwidth = 2;
			gridBagConstraints.gridx = 1;
			mainPanel = new JPanel();
			mainPanel.setLayout(new GridBagLayout());
			mainPanel.setName("mainPanel");
			mainPanel.add(getTfInitialDirectory(), gridBagConstraints);
			mainPanel.add(getBtnBrowser(), gridBagConstraints1);
			mainPanel.add(getFcOpenDirectory(), gridBagConstraints2);
			mainPanel.add(lblInitialDirectory, gridBagConstraints11);
			mainPanel.add(getBtnSave(), gridBagConstraints21);
			mainPanel.add(getBtnCancel(), gridBagConstraints3);
		}
		return mainPanel;
	}

	/**
	 * This method initializes tfInitialDirectory
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfInitialDirectory() {
		if (tfInitialDirectory == null) {
			tfInitialDirectory = new JTextField();
			tfInitialDirectory.setPreferredSize(new Dimension(150, 20));
		}
		return tfInitialDirectory;
	}

	/**
	 * This method initializes btnBrowser
	 * @return javax.swing.JButton
	 */
	private JButton getBtnBrowser() {
		if (btnBrowser == null) {
			btnBrowser = new JButton();
			btnBrowser.setText("...");
			btnBrowser.setPreferredSize(new Dimension(30, 20));
			btnBrowser.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					openFileChooser();
				}
			});
		}
		return btnBrowser;
	}

	/**
	 * This method initializes fcOpenDirectory
	 * @return javax.swing.JFileChooser
	 */
	private JFileChooser getFcOpenDirectory() {
		if (fcOpenDirectory == null) {
			fcOpenDirectory = new JFileChooser();
			fcOpenDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			fcOpenDirectory.setDialogTitle("Select Directory");
			fcOpenDirectory.setControlButtonsAreShown(true);
			fcOpenDirectory.setVisible(false);
		}
		return fcOpenDirectory;
	}

	private void openFileChooser() {
		fcOpenDirectory.setVisible(true);
		int returnval = fcOpenDirectory.showOpenDialog(MainWindow.this);
		if (returnval == JFileChooser.APPROVE_OPTION) {
			tfInitialDirectory.setText(fcOpenDirectory.getSelectedFile().getAbsolutePath());
		}
	}

	/**
	 * This method initializes btnSave
	 * @return javax.swing.JButton
	 */
	private JButton getBtnSave() {
		if (btnSave == null) {
			btnSave = new JButton();
			btnSave.setText("Save");
			btnSave.setPreferredSize(new Dimension(100, 20));
		}
		return btnSave;
	}

	/**
	 * This method initializes btnCancel
	 * @return javax.swing.JButton
	 */
	private JButton getBtnCancel() {
		if (btnCancel == null) {
			btnCancel = new JButton();
			btnCancel.setText("Cancel");
			btnCancel.setPreferredSize(new Dimension(100, 20));
		}
		return btnCancel;
	}
} // @jve:decl-index=0:visual-constraint="10,10"
